package com.zhaoxi.project.fms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.fms.domain.FmsBill;
import com.zhaoxi.project.fms.service.impl.FmsBillServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 财务单据Controller
 * 
 * @author zhaoxi
 * @date 2023-08-14
 */
@RestController
@RequestMapping("/fms/bill")
public class FmsBillController extends BaseController
{
    @Autowired
    private FmsBillServiceImpl fmsBillService;

    /**
     * 查询财务单据列表
     */
    @PreAuthorize("@ss.hasPermi('fms:bill:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsBill fmsBill)
    {
        startPage();
        List<FmsBill> list = fmsBillService.selectFmsBillList(fmsBill);
        return getDataTable(list);
    }

    /**
     * 导出财务单据列表
     */
    @PreAuthorize("@ss.hasPermi('fms:bill:export')")
    @Log(title = "财务单据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmsBill fmsBill)
    {
        List<FmsBill> list = fmsBillService.selectFmsBillList(fmsBill);
        ExcelUtil<FmsBill> util = new ExcelUtil<FmsBill>(FmsBill.class);
        util.exportExcel(response, list, "财务单据数据");
    }

    /**
     * 获取财务单据详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:bill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fmsBillService.selectFmsBillById(id));
    }

    /**
     * 新增财务单据
     */
    @PreAuthorize("@ss.hasPermi('fms:bill:add')")
    @Log(title = "财务单据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmsBill fmsBill)
    {
        return toAjax(fmsBillService.insertFmsBill(fmsBill));
    }

    /**
     * 修改财务单据
     */
    @PreAuthorize("@ss.hasPermi('fms:bill:edit')")
    @Log(title = "财务单据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmsBill fmsBill)
    {
        return toAjax(fmsBillService.updateFmsBill(fmsBill));
    }

    /**
     * 删除财务单据
     */
    @PreAuthorize("@ss.hasPermi('fms:bill:remove')")
    @Log(title = "财务单据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fmsBillService.deleteFmsBillByIds(ids));
    }
}
